/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.unibo.as.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;

/**
 *
 * @author Johnny
 */



public class LoginForm extends Composite {

    private final FlexTable layout;
    private final DecoratorPanel dp;
    public  TextBox loginBox;
    public  PasswordTextBox pwdBox;

    public final Button loginBtn;
    public final Button loginGoogleBtn;
    public final Button signupBtn;

    public final Label infoLabel;


    public LoginForm() {
        final MainPanel parent = (MainPanel) getParent();

        layout = new FlexTable();
        layout.setCellSpacing(6);
        dp = new DecoratorPanel();

        loginBox = new TextBox();
        layout.setHTML(0, 0, "User: ");
        layout.setWidget(0, 1, loginBox);

        pwdBox = new PasswordTextBox();

        layout.setHTML(1, 0, "Password: ");

        layout.setWidget(1, 1, pwdBox);


        loginBtn = new Button();
        loginGoogleBtn = new Button();
        signupBtn = new Button();

        infoLabel = new Label();

        

        loginBtn.setText("SignIn");
        loginGoogleBtn.setText("Google SignIn");

        HorizontalPanel signInBtns = new HorizontalPanel();
        signInBtns.add(loginBtn);
        signInBtns.add(loginGoogleBtn);

        layout.setWidget(2, 1, signInBtns);

        signupBtn.setText("SignUp");
        layout.setHTML(4, 0, "Need Account?");
        layout.setWidget(4, 1, signupBtn);

        layout.setWidget(5,1,infoLabel);

        dp.setWidget(layout);
        initWidget(dp);

        pwdBox.addKeyPressHandler(new KeyPressHandler(){
            @Override
            public void onKeyPress(KeyPressEvent event) {
                if(event.getCharCode()== 13){
                    parent.LoginClick();
                }
            }

        });

        loginBtn.addClickHandler(new ClickHandler(){
            @Override
                public void onClick(ClickEvent event) {
                    parent.LoginClick();
                }
            });

        loginGoogleBtn.addClickHandler(new ClickHandler(){
            @Override
                public void onClick(ClickEvent event) {
                    parent.LoginGoogleClick();
                }
            });

        signupBtn.addClickHandler(new ClickHandler(){
            @Override
                public void onClick(ClickEvent event) {
                    parent.SignupClick();
                }
            });
    }



}



/*
 * FlexTable layout = new FlexTable();
                
 */